package com.seafwg.user;

import com.seafwg.config.SpringConfiguration;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @Author seafwg
 * @Date 2022/2/11 3:11 下午
 * @Version 1.0
 * @description spring 集成JUnit4
 * //@RunWith 加载SpringJUnit4类文件
 * //@ContextConfiguration 加载spring核心配置类文件
 * //可以用其他注解@Autowired注入容器的bean可直接注入
 */

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {SpringConfiguration.class})
public class UserTest1 {

    @Autowired
    private DataSource dataSource;

    @Test
    public void test() throws SQLException {
        Connection connection = dataSource.getConnection();
        System.out.println("======================");
        System.out.println(connection);
        connection.close();
    }

}
